package com.niit.plugins;

import com.niit.entity.Student;
import com.niit.mapper.StudentMapper;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.lang.reflect.Method;

// ExamplePlugin.java
@Intercepts(
        {@Signature(type= Executor.class, method = "query",
                 args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})})
public class LogPlugin implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {

//        Method method = invocation.getMethod();

        System.out.println("Do Something before Execute SQL");

        // executeQuery方法 实际调用/执行
        Object result = invocation.proceed();

        System.out.println("Do Something After Execute SQL");
        return result;
    }
}